/**
 * Created by yerdos on 2015/9/10.
 */
app.controller('UserCtrl', ['$scope',  '$rootScope',
  function ($scope, ngTableParams, $rootScope) {
    //$scope.infos = [];
   var basurl="http://www.daraboz.net/";

    $scope.regUser = function () {
      if ($scope.userInfo == null || $scope.userInfo.user_name == null && $scope.userInfo.password == null) {
        alert("请先填写用户信息！");
        return;
      }

      apiHelper.callService(basurl + 'User/reg', "GET", { uerName: $scope.userInfo.user_name, password: $scope.userInfo.password }).then(function (data) {
        $scope.isReg = data;
        if(data)
        {
          alert("注册成功！");
        }
        else
        {
          alert("失败！");
        }
      });
    }


    $scope.getUserInfo = function () {
      if ($scope.userInfo == null || $scope.userInfo.user_name == null && $scope.userInfo.password == null) {
        alert("请先填写用户信息！");
        return;
      }

      apiHelper.callService(basurl + 'User/reg', "GET", { uerName: $scope.userInfo.user_name, password: $scope.userInfo.password }).then(function (data) {
        if(data==null)
        {
          alert("用户信息获取失败!");
        }
        else
        {
          $scope.userInfo = data;
        }
      });
    }


    $scope.login = function () {
      if ($scope.userInfo == null || $scope.userInfo.log_user == null && $scope.userInfo.log_pwd == null) {
        alert("请先填写用户信息！");
        return;
      }

      apiHelper.callService(basurl + 'User/reg', "GET", { log_user: $scope.userInfo.log_user, log_pwd: $scope.userInfo.log_pwd,auto: $scope.userInfo.auto }).then(function (data) {
        $scope.isReg = data;
        if(data)
        {
          alert("注册成功！");
        }
        else
        {
          alert("失败！");
        }
      });
    }

  }]);
